package com.kgcx.organization.service;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.CityUtils;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.StationExit;
import com.kgcx.organization.mapper.StationExitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StationExitService {
    @Autowired
    private StationExitMapper stationExitMapper;

    public StationExit getStationExit(Long kid) {
        return stationExitMapper.selectByPrimaryKey(kid);
    }

    public List<StationExit> getStationExitList(RequestData rd) {
        rd.put("cityId", CityUtils.getCityId(rd));
        PageUtils.page(rd);
        return stationExitMapper.getStationExitList(rd);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addStationExit(StationExit stationExit) {
        stationExitMapper.insertSelective(stationExit);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateStationExit(StationExit stationExit) {
        stationExitMapper.updateByPrimaryKeySelective(stationExit);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeStationExit(Long kid) {
        StationExit stationExit = new StationExit();
        stationExit.setKid(kid);
        stationExit.setStatus(Cons.COMMON_STATUS_DELETE);
        stationExitMapper.updateByPrimaryKeySelective(stationExit);
    }
}
